#include "StdAfx.h"
#include "GameStates.h"
#include "../Game/DWorld.h"
#include "../Game/DGame.h"
#include "../Engine/Postprocess/DPostprocessManager.h"
#include "../Engine/DInput.h"
#include "../Engine/DAnimation.h"
#include "../Engine/DIRenderer.h"
#include "../Engine/DIResourceManager.h"
#include "../Actors/DPlayer.h"
#include "../Actors/DBackground.h"

using namespace GameStates;

IState::IState(void)
{
}

IState::~IState(void)
{
}

////////// INTRO //////////////

void Intro::enter(boost::shared_ptr<DGame> game)
{

}

void Intro::update(float dt, boost::shared_ptr<DGame> game)
{

}

void Intro::render(boost::shared_ptr<DGame> game)
{

}

void Intro::exit(boost::shared_ptr<DGame> game)
{

}

//////////// LOADING ///////////////

void Loading::enter(boost::shared_ptr<DGame> game)
{
    m_back.reset(new DBackground(game->globalResourceManager()->animation("Backgrounds/Loading")));

    m_bLoading = true;
    game->advanceWorld(m_bLoading);
}

void Loading::update(float dt, boost::shared_ptr<DGame> game)
{
    // loading finished -> start world
    if(m_bLoading == false)
    {
        game->changeState(Playing::instance());
    }
}

void Loading::render(boost::shared_ptr<DGame> game)
{
    // draw loading screen
    game->renderer()->render(m_back);
}

void Loading::exit(boost::shared_ptr<DGame> game)
{

}

//////////// PLAYING ///////////////

void Playing::enter(boost::shared_ptr<DGame> game)
{
    PostprocessManager::instance().activateFadeIn(0.2f);
}

void Playing::update(float dt, boost::shared_ptr<DGame> game)
{
	game->world()->update(dt);
    PostprocessManager::instance().update(dt);
}

void Playing::render(boost::shared_ptr<DGame> game)
{
    game->world()->render(game->renderer());
    PostprocessManager::instance().render(game->renderer());
}

void Playing::exit(boost::shared_ptr<DGame> game)
{

}